<%--
  Created by IntelliJ IDEA.
  User: 杨威
  Date: 2021/9/22
  Time: 20:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<input type="text" id="userName"/><br/>
<input type="text" id="passWord"/>
<span id="sp"></span><br/>
<button onclick="logins()">登录</button>
<script type="text/javascript">

    function logins() {
        var userName = document.getElementById("userName");
        var passWord = document.getElementById("passWord");
        var sp = document.getElementById("sp");
        var xhr=new XMLHttpRequest();
        xhr.onreadystatechange=function () {
            if(xhr.readyState==4&&xhr.status==200){
                var text = xhr.responseText;
                console.log(text)
                if(text==1){
                    sp.innerText="登录成功"
                }else {
                    sp.innerText="登录失败"
                }
            }
        }
        console.log(22)
        xhr.open("post","testPost",true)
        xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded")
        xhr.send("userName="+userName.value+"&&passWord="+passWord.value)
    }
</script>

</body>
</html>
